# Agent 打包脚本 - 简化版
# 使用方式：.\pack_simple.ps1

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Agent 项目打包" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

# 进入agent目录
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir

# 检查main.py
if (-not (Test-Path "main.py")) {
    Write-Host "错误: 未找到 main.py" -ForegroundColor Red
    exit 1
}

# 删除旧压缩包
if (Test-Path "agent.tar.gz") {
    Write-Host "删除旧的压缩包..." -ForegroundColor Yellow
    Remove-Item "agent.tar.gz" -Force
}

Write-Host "正在打包..." -ForegroundColor Blue

# 使用tar命令打包
tar -czf agent.tar.gz --exclude=__pycache__ --exclude=*.pyc --exclude=logs --exclude=screenshots --exclude=.git --exclude=state.json --exclude=agent.tar.gz --exclude=pack_agent.sh --exclude=pack_agent.ps1 --exclude=pack_simple.ps1 *

if ($LASTEXITCODE -eq 0) {
    $fileSize = (Get-Item "agent.tar.gz").Length / 1MB
    $fileSizeMB = [math]::Round($fileSize, 2)
    
    Write-Host ""
    Write-Host "✅ 打包成功！" -ForegroundColor Green
    Write-Host "   文件: agent.tar.gz" -ForegroundColor Green
    Write-Host "   大小: $fileSizeMB MB" -ForegroundColor Green
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Cyan
    Write-Host "下一步操作：" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "1. 上传到控制端服务器：" -ForegroundColor Blue
    Write-Host "   scp agent.tar.gz root@your-server:/tmp/" -ForegroundColor Gray
    Write-Host ""
    Write-Host "2. 在管理后台进行部署：" -ForegroundColor Blue
    Write-Host "   - 进入【服务器管理】菜单" -ForegroundColor Gray
    Write-Host "   - 选择要部署的服务器" -ForegroundColor Gray
    Write-Host "   - 点击【批量部署Agent】按钮" -ForegroundColor Gray
    Write-Host "   - 填写文件路径：/tmp/agent.tar.gz" -ForegroundColor Gray
    Write-Host "   - 开始部署" -ForegroundColor Gray
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Cyan
} else {
    Write-Host "❌ 打包失败" -ForegroundColor Red
    Write-Host "错误代码: $LASTEXITCODE" -ForegroundColor Red
    exit 1
}

